package com.gin.kotlin.gf2gamecommunity.routes

import androidx.compose.animation.core.tween
import androidx.compose.animation.slideInHorizontally
import androidx.compose.animation.slideOutHorizontally
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavGraphBuilder
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import com.gin.kotlin.gf2gamecommunity.base.composable.ImagePreViewer
import kotlinx.serialization.Serializable


/**
 * 扩展方法
 * @receiver [NavGraphBuilder]
 */
fun NavGraphBuilder.imagePreView() = composable<ImagePreViewRoute>(
    // 从屏幕右侧进入，持续500毫秒
    enterTransition = { slideInHorizontally(tween(500)) { it } },
    // 从屏幕右侧退出，持续500毫秒
    exitTransition = { slideOutHorizontally(tween(500)) { it } }) {
    ImagePreViewComposable(route = it.toRoute())
}

/**
 * 图片预览路线
 * @param url 需要展示的图片的url
 * @param urls 如果需要翻页功能传入此项, url参数需出现在其中
 * @constructor
 */
@Serializable
data class ImagePreViewRoute(
    val url: String,
    val urls: List<String> = listOf(url)
)

@Composable
fun ImagePreViewComposable(route: ImagePreViewRoute) {
    ImagePreViewer(urls = route.urls, initialUrl = route.url, modifier = Modifier.fillMaxSize(), dir = "gf2_game_community")
}